<?php

class Rzd_Validate_TimeComparisonInDynamicElement extends Zend_Validate_Abstract
{
    const START_TIME_SHOULD_BE_LESS = 'startTimeShouldBeLess';

    protected $_startTime;
    protected $_endTime;

    protected $_messageVariables = array(
        'start_time' => '_startTime',
        'ednt_time' => '_endTime'
    );

    protected $_messageTemplates = array(
        START_TIME_SHOULD_BE_LESS => "Start time - %start_time% should be less end time - %ednt_time%",
    );

    public function __construct(){ }

    public function isValid($value, $context=null)
    {
        foreach($value['data'] as $index => $dayElementValue) {
            if($dayElementValue['start_time'] > $dayElementValue['end_time']) {
                $this->setStartTime($dayElementValue['end_time']);
                $this->setEndTime($dayElementValue['end_time']);
                $this->_error(START_TIME_SHOULD_BE_LESS);
                return false;
            }
        }
        return true;
    }

    public function setEndTime($endTime) {
        $this->_endTime = $endTime;
    }

    public function getEndTime() {
        return $this->_endTime;
    }

    public function setStartTime($startTime) {
        $this->_startTime = $startTime;
    }

    public function getStartTime() {
        return $this->_startTime;
    }
}